﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

public partial class ssws : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
			Socut.Reader sqlDataReader = new Socut.Reader("select top 10 id,title,addtime from web_notice where smallclassid=9 order by addtime desc,id desc ");
			show_new_list.InnerHtml += "<table width='100%' border='0' align='left' cellpadding='0' cellspacing='0' class='bluelink'>";
			while (sqlDataReader.Read())
			{
			show_new_list.InnerHtml += "<tr><td height='25'><img src='images/arrowgrey-r.gif'>&nbsp;<a href='lawview.aspx?ID=" + sqlDataReader["id"].ToString() + "' target='_blank' title='" + sqlDataReader["title"].ToString() + "'>" + getStr(sqlDataReader["title"].ToString(), 50) + "</a></td></tr>";
			}
			show_new_list.InnerHtml += "</table>";
			sqlDataReader.Close();
		}

    }

    /// <summary>
    /// 去除HTML标签
    /// </summary>
    /// <param name="RContent">要去除标签的文本</param>
    /// <returns></returns>
    public string Clear_HTML_Code(string RContent)
    {
        int index1 = RContent.IndexOf("<STYLE>");
        if (index1 >= 0)
        {
            int index2 = RContent.LastIndexOf("</STYLE>");
            if (index2 > index1)
            {
               RContent=RContent.Remove(index1, index2 - index1);
            }
        }
        RContent = Regex.Replace(RContent, "<[^>]+>", "");
        
        return RContent;
    }
    public static string getStr(string s, int l)
    {
        string temp = s;
        temp = temp.Replace("<div>", "");
        temp = temp.Replace("&nbsp;", "");
        temp = temp.Replace("</div>", "");
		
        if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= l)
        {
            return temp;
        }
        for (int i = temp.Length; i >= 0; i--)
        {
            temp = temp.Substring(0, i);
            if (Regex.Replace(temp, "[\u4e00-\u9fa5]", "zz", RegexOptions.IgnoreCase).Length <= l - 3)
            {
                return temp + "";
            }
        }
        return "";
    }

public string CutString(string str,int length)
        {
            int i = 0, j = 0;
            foreach(char chr in str)
            {
                if((int)chr > 127)
                {
                    i += 2;
                }
                else
                {
                    i ++;
                }
                if (i > length)
                {
                    str = str.Substring(0, j) + "…";
                    break;
                }
                j ++;
            }
            return str;
        } 
    public string htmlstr(string chr)
    {
        if (chr == null)
            return "";
        //chr = chr.Replace("<", "&lt");
        //chr = chr.Replace(">", "&gt");
        chr = chr.Replace("\n", "<br>");
        //chr = chr.Replace("\"", "&quot;");
        //chr = chr.Replace("'", "&#39;");
        chr = chr.Replace(" ", "&nbsp;");
        chr = chr.Replace("select", "");
        chr = chr.Replace("delete", "");
        chr = chr.Replace("update", "");
        chr = chr.Replace("drop", "");
        //chr = chr.Replace(";", "");
        //chr = chr.Replace("(", "");
        //chr = chr.Replace(")", "");
        chr = chr.Replace("and", "");
        chr = chr.Replace("or", "");
        //chr = chr.Replace("\r", "");
        return (chr);
    }

}
